package com.css.fxfzypg.modules.model.controller;

import com.css.fxfzypg.base.response.RestResponse;
import com.css.fxfzypg.modules.model.entity.Casualty;
import com.css.fxfzypg.modules.model.entity.ResettlementPersonnel;
import com.css.fxfzypg.modules.model.service.ResettlementPersonnelService;
import com.css.fxfzypg.modules.model.to.CasualtyTO;
import com.css.fxfzypg.modules.model.vo.CasualtyVO;
import com.css.fxfzypg.modules.model.vo.ResettlementPersonnelVO;
import com.css.fxfzypg.util.PlatformPageUtils;
import com.css.fxfzypg.util.ResponseCreator;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.Map;

/**
 * @author Dbj
 * @date 2022年10月05日  16:12
 * 需安置人员计算模型
 */
@RestController
@Validated
@RequestMapping("/resettlement")
public class ResettlementPersonnelController {

    @Resource
    private ResettlementPersonnelService resettlementPersonnelService;

    /***
     * 需安置人员计算模型列表分页查询
     * @param vo
     */
    @GetMapping("/page")
    public RestResponse getPage(ResettlementPersonnelVO vo, HttpServletRequest request){
        int curPage = Integer.parseInt(request.getParameter(PlatformPageUtils.CUR_PAGE));
        int pageSize=Integer.parseInt(request.getParameter(PlatformPageUtils.PAGE_SIZE));
        Map<String,Object> page=resettlementPersonnelService.getPage(vo,curPage,pageSize);
        return ResponseCreator.createSuccessResponse(page,"查询成功!");
    }
    /***
     * 需安置人员计算模型id查询信息
     * @param id
     */
    @GetMapping("/getModelById")
    public RestResponse getModelById(@NotBlank(message="模型id不能为空") @RequestParam("id") String id){
        ResettlementPersonnel model = resettlementPersonnelService.getModelById(id);
        return ResponseCreator.createSuccessResponse(model);
    }

    /***
     * 需安置人员计算模型查询信息用于复制信息回显
     * @param id
     */
    @GetMapping("/getModelByIdForCopy")
    public RestResponse getModelByIdForCopy(@NotBlank(message="模型id不能为空") @RequestParam("id") String id){
        ResettlementPersonnel resettlementPersonnel = resettlementPersonnelService.getModelByIdForCopy(id);
        return ResponseCreator.createSuccessResponse(resettlementPersonnel);
    }

    /***
     * 需安置人员计算模型-用于复制保存
     * @param resettlementPersonnel
     */
    @PostMapping("/save")
    public RestResponse save(@Valid @RequestBody ResettlementPersonnel resettlementPersonnel){
        resettlementPersonnelService.save(resettlementPersonnel);
        return ResponseCreator.createSuccessResponse("","保存成功");
    }

    /***
     * 需安置人员计算模型-修改
     * @param resettlementPersonnel
     */
    @PostMapping("/update")
    public RestResponse update(@Valid @RequestBody ResettlementPersonnel resettlementPersonnel){
        resettlementPersonnelService.update(resettlementPersonnel);
        return ResponseCreator.createSuccessResponse("","保存成功");
    }

    /***
     * 需安置人员计算模型-删除
     * @param vo
     */
    @PostMapping("/delete")
    public RestResponse delete(@RequestBody ResettlementPersonnelVO vo){
        resettlementPersonnelService.delete(vo.getId());
        return ResponseCreator.createSuccessResponse("","删除成功");
    }
}
